package com.eightywork.life.activity;

import cn.jpush.android.api.JPushInterface;

import com.eightywork.life.R;
import com.umeng.analytics.MobclickAgent;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

public class RegSecondActivity extends BaseActivity implements OnClickListener {
	private EditText seccode, password;
	private ImageButton returnButton;
	private Button regButton;
	private String username;
	private AsyncTask task;
	public static RegSecondActivity activity = null;
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_reg2);
		initView();
		initData();
		activity = this;
	}

	private void initData() {
		username = getIntent().getStringExtra("account");
	}

	@Override
	protected void onDestroy() {
		if (task != null)
			task.cancel(true);
		super.onDestroy();
	}
	
	@Override
	public void onResume() {		
		super.onResume();
		JPushInterface.onResume(this);
	    MobclickAgent.onResume(this);
	}
	
	@Override
	public void onPause() {
	    super.onPause();
		JPushInterface.onPause(this);
	    MobclickAgent.onPause(this);
	}

	public void initView() {
		seccode = (EditText) findViewById(R.id.seccode);
		password = (EditText) findViewById(R.id.password);
		returnButton = (ImageButton) findViewById(R.id.button_left);
		regButton = (Button) findViewById(R.id.reg_button);
		returnButton.setOnClickListener(this);
		regButton.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v == returnButton) {
			
			finish();
		} else if (v == regButton) {
			reg();
			hideKeyBoard(activity);
		}
	}

	private void reg() {
		String seccodeString = seccode.getEditableText().toString();
		String passwordString = password.getEditableText().toString();
		if (seccodeString.equals("")) {
			seccode.setError(Html.fromHtml("<font color=red>请填写验证码</font>"));
			return;
		}
		if (passwordString.equals("")) {
			password.setError(Html.fromHtml("<font color=red>请填写密码</font>"));
			return;
		}
		Intent intent = new Intent(context, LoginMapActivity.class);
		intent.putExtra("username", username);
		intent.putExtra("seccode", seccodeString);
		intent.putExtra("password", passwordString);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);
	}
}
